package com.mercury.pattern._13_command;

/**
 * 遥控器
 */
public class RemoteController {
    Command[] offCommands;
    Command[] onCommands;

    //记录撤销的命令
    Command undoCommand;

    public RemoteController() {
        offCommands = new Command[6];
        onCommands = new Command[6];
    }

    public void offBtn(int no){
        offCommands[no].execute();
        //记录这次的命令，如果有撤销即可撤销
        undoCommand = offCommands[no];
    }

    public void onBtn(int no){
        onCommands[no].execute();
        undoCommand = offCommands[no];
    }

    public void undoBtn(){
        undoCommand.undo();
    }

    public void setCommand(int no,Command onCommand,Command offCommand){
        onCommands[no] = onCommand;
        offCommands[no] = offCommand;
    }

}
